<template>
	<view>
		<view class="top">
			<u-button type="primary" text="+ 新增优惠劵" @click="todetail" style="background-color: white; 
                             color: #2f81fa; 
                             display: flex;
                             align-items: center;
                             justify-content: center;
                             font-size: 50rpx!important; 
                             font-weight: 500;
                             border-radius: 100rpx; 
                             ">
			</u-button>
		</view>

		<uni-card style="position: relative; top: -280rpx; border-radius: 30rpx;">

			<view class="uni-padding-wrap uni-common-mt">
				<uni-segmented-control :current="current" :values="items" :style-type="styleType"
					:active-color="activeColor" @clickItem="onClickItem" class="rounded-segmented-control" />
			</view>
			<view class="content">
				<view v-if="current === 0">
					<view v-for="item in couponList">
						<view class="youhui" v-if="item.type==0&&item.state==0">
							<view class="left">
								<view style="font-size: 28rpx;">满{{item.full}}元可用</view>
								<view style="display: flex; position: relative; top: 40rpx; left: 30rpx;">
									<view style="font-size: 30rpx; position: relative; top: 20rpx;">￥ </view>
									<view style="font-size: 98rpx; font-weight: 600;">{{item.reduce}}</view>
								</view>
							</view>

							<view class="right">
								<view style="font-size: 26rpx; margin-bottom: 10rpx;">优惠劵名称：{{item.name}}</view>
								<view style="font-size:26rpx;font-weight:200;margin-bottom: 20rpx;">
									{{item.useTime}}~{{item.useendTime}}
								</view>

								<view style="font-size: 26rpx; font-weight: 200;">每人限领{{item.limited}}张</view>
							</view>
						</view>
						<view class="youhui" v-if="item.type==1&&item.state==0">
							<view class="left">
								<!-- <view style="font-size: 28rpx;">满{{item.full}}元可用</view> -->
								<view style="display: flex; position: relative; top: 40rpx; left: 30rpx;">
									<view style="font-size: 30rpx; position: relative; top: 20rpx;left:90rpx">折 </view>
									<view style="font-size: 98rpx; font-weight: 600;">{{item.discount}}</view>
								</view>
							</view>

							<view class="right">
								<view style="font-size: 26rpx; margin-bottom: 10rpx;">优惠劵名称：{{item.name}}</view>
								<view style="font-size:26rpx;font-weight:200;margin-bottom: 20rpx;">
									{{item.useTime}}~{{item.useendTime}}
								</view>

								<view style="font-size: 26rpx; font-weight: 200;">每人限领{{item.limited}}张</view>
							</view>
						</view>
					</view>

				</view>
				<view v-if="current === 1">

					<view v-for="item in couponList">
						<view class="youhui_false" v-if="item.type==0&&item.state==1">
							<view class="left">
								<view style="font-size: 28rpx;">满{{item.full}}元可用</view>
								<view style="display: flex; position: relative; top: 40rpx; left: 30rpx;">
									<view style="font-size: 30rpx; position: relative; top: 20rpx;">￥ </view>
									<view style="font-size: 98rpx; font-weight: 600;">{{item.reduce}}</view>
								</view>
							</view>

							<view class="right">
								<view style="font-size: 26rpx; margin-bottom: 10rpx;">{{item.name}}</view>
								<view style="font-size:26rpx;font-weight:200;margin-bottom: 20rpx;">
									{{item.useTime}}~{{item.useendTime}}
								</view>

								<view style="font-size: 26rpx; font-weight: 200;">每人限领{{item.limited}}张</view>
								<image src="../../static/falsetimecopy.svg"
									style="width: 140rpx; height: 140rpx; float: right; top: -100rpx;"></image>
							</view>
						</view>

						<view class="youhui_false" v-if="item.type==1&&item.state==1">
							<view class="left">
								<!-- <view style="font-size: 28rpx;">满{{item.full}}元可用</view> -->
								<view style="display: flex; position: relative; top: 40rpx; left: 30rpx;">
									<view style="font-size: 30rpx; position: relative; top: 20rpx;left: 90rpx;">折
									</view>
									<view style="font-size: 98rpx; font-weight: 600;">{{item.discount}}</view>
								</view>
							</view>

							<view class="right">
								<view style="font-size: 26rpx; margin-bottom: 10rpx;">{{item.name}}</view>
								<view style="font-size:26rpx;font-weight:200;margin-bottom: 20rpx;">
									{{item.useTime}}~{{item.useendTime}}
								</view>

								<view style="font-size: 26rpx; font-weight: 200;">每人限领{{item.limited}}张</view>
								<image src="../../static/falsetimecopy.svg"
									style="width: 140rpx; height: 140rpx; float: right; top: -100rpx;"></image>
							</view>
						</view>
					</view>
				</view>
			</view>
		</uni-card>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				items: ['进行中', '已结束'],
				colors: ['#007aff', '#4cd964', '#dd524d'],
				current: 0,
				activeColor: '#007aff',
				styleType: 'button',
				couponList: [],
				shopId: '',
			}
		},
		onLoad() {
			this.shopId = uni.getStorageSync("shopId");
			this.getList()
		},
		methods: {
			getList() {
				let that = this
				this.$http({
					url: '/api/shop/coupon/list?shopId=' + this.shopId,
					method: 'GET',
					success(res) {
						that.couponList = res.data.rows
						console.log(that.couponList)
					}
				})
			},
			todetail() {
				uni.navigateTo({
					url: '../hjjfaquan/hjjfaquan'
				});
			},


			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
				}
			},
			styleChange(e) {
				if (this.styleType !== e.detail.value) {
					this.styleType = e.detail.value
				}
			},
			colorChange(e) {
				if (this.styleType !== e.detail.value) {
					console.log(e.detail.value);
					this.activeColor = e.detail.value
				}
			}
		}
	}
</script>

<style lang="scss">
	.youhui_false {
		margin-top: 40rpx;
		width: 100%;
		height: 220rpx;
		display: flex;
		opacity: 0.3;

		.left {
			border-bottom-left-radius: 8%;
			border-top-left-radius: 8%;
			text-align: center;
			padding: 30rpx 0;
			width: 35%;
			color: #fff;
			background-color: #ff7e48;
		}

		.right {

			padding: 30rpx 0rpx;
			padding-left: 20rpx;
			color: black;
			border-top-right-radius: 8%;
			border-bottom-right-radius: 8%;
			width: 65%;
			background-color: #fff3eb;
		}
	}

	.youhui {

		margin-top: 40rpx;
		width: 100%;
		height: 220rpx;
		display: flex;


		.left {
			border-bottom-left-radius: 8%;
			border-top-left-radius: 8%;
			text-align: center;
			padding: 30rpx 0;
			width: 35%;
			color: #fff;
			background-color: #ff7e48;
		}

		.right {

			padding: 30rpx 0rpx;
			padding-left: 20rpx;
			color: black;
			border-top-right-radius: 8%;
			border-bottom-right-radius: 8%;
			width: 65%;
			background-color: #fff3eb;
		}
	}

	.top {
		padding-right: 20rpx;
		padding-left: 20rpx;
		height: 360rpx;
		background-color: #2f81fa;
		padding-top: 60rpx;
	}

	.uni-common-mt {
		margin-top: 10rpx;
	}

	.uni-padding-wrap {

		width: 350rpx;
		padding: 0px 70px;
	}

	.rounded-segmented-control {
		border-radius: 15rpx;
	}
</style>